package com.cybertron.ironhide.manage.action;

import java.util.List;

import javax.annotation.Resource;

import com.cybertron.ironhide.manage.common.base.BaseAction;
import com.cybertron.ironhide.manage.domain.Alliance;
import com.cybertron.ironhide.manage.service.AllianceService;

public class AllianceAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6150551925972200898L;

	@Resource
	private AllianceService allianceService;

	private List<Alliance> alliances;

	private Alliance alliance;

	public String list() {
		alliances = allianceService.selectBySelective(alliance, pager);
		return LIST;
	}

	public String add() {
		return ADD;
	}

	public String doAdd() {
		allianceService.insertSelective(alliance);
		return ajaxSuccess("添加成功", "alliance-list", null, CLOSE_CURRENT);
	}

	public String delete() {
		allianceService.deleteByPrimaryKey(alliance.getId());
		return ajaxSuccess("删除成功", "alliance-list");
	}

	public String edit() {
		alliance = allianceService.selectByPrimaryKey(alliance.getId());
		return EDIT;
	}

	public String doEdit() {
		allianceService.updateByPrimaryKeySelective(alliance);
		return ajaxSuccess("编辑成功", "alliance-list", null, CLOSE_CURRENT);
	}

	public String taskAdd() {
		allianceService.insertTaskSelective(alliance.getId());
		return ajaxSuccess("添加任务成功", "category-view", "cagegory-list-box");
	}

	public String checkTitle() {
		boolean isValid = allianceService.checkTitle(alliance.getTitle());
		if (isValid) {
			return ajaxText("false");
		} else {
			return ajaxText("true");
		}
	}

	public Alliance getAlliance() {
		return alliance;
	}

	public void setAlliance(Alliance alliance) {
		this.alliance = alliance;
	}

	public List<Alliance> getAlliances() {
		return alliances;
	}

}
